fig<-plot_ly(data = databub[-7,], 
        z = ~I(data_2020 -data_2008), 
        x = ~I(mpower_all_2020 - mpower_all_2008), 
        y = ~data_2008,
        size = ~mpower_all_2008,
        text = countries[-7],
    #    color = ~data_2008,
   #     colors = colorRampPalette(c("green", "red")),
        marker = list(symbol = "circle", 
                      sizemode = 'diameter',
                      color = ~(HDI_MHI),
                      reversescale = FALSE,
                      colorscale = "YlOrRd", #"Viridis",  # Specify the desired color scale
                      showscale = TRUE),
        sizes  = c(5, 60)
        ) 

fig<-fig%>%add_markers()
fig <- fig %>% add_text(
  x = ~I(mpower_all_2020 - mpower_all_2008),
  y = ~data_2008,
  z = ~I(data_2020 - data_2008),
  text = ~countries[-7],
  textposition = "top center",
  textfont = list(size = 12),  # Increase the text size to 12
  showlegend = FALSE
)
fig<-fig%>% layout(scene = list(
                      zaxis = list(title = "Difference in Smoking prevalence (2020-2008) (%)"),
                      xaxis = list(title = "Difference in MPOWER scores (2020-2008)"),
                      yaxis = list(title = "Baseline prevalence 2008 (%)")))
fig
## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.
## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...
fig<-plot_ly(data = databub[-7,], 
        z = ~I(data_2020 -data_2008), 
        x = ~I(mpower_all_2020 - mpower_all_2008), 
        y = ~data_2008,
        size = ~mpower_all_2008,
        text = countries[-7],
    #    color = ~data_2008,
   #     colors = colorRampPalette(c("green", "red")),
        marker = list(symbol = "circle", 
                      sizemode = 'diameter',
                      color = ~(HDI_MHI),
                      reversescale = FALSE,
                      colorscale = "YlOrRd", #"Viridis",  # Specify the desired color scale
                      showscale = TRUE),
        sizes  = c(5, 60)
        ) 

fig<-fig%>%add_markers()
fig <- fig %>% add_text(
  x = ~I(mpower_all_2020 - mpower_all_2008),
  y = ~data_2008,
  z = ~I(data_2020 - data_2008),
  text = ~countries[-7],
  textposition = "top center",
  textfont = list(size = 12),  # Increase the text size to 12
  showlegend = FALSE
)
fig<-fig%>% layout(scene = list(
                      zaxis = list(title = "Difference in Smoking prevalence (2020-2008) (%)"),
                      xaxis = list(title = "Difference in MPOWER scores (2020-2008)"),
                      yaxis = list(title = "Baseline prevalence 2008 (%)")))
fig
## Warning: `line.width` does not currently support multiple values.

## Warning: `line.width` does not currently support multiple values.
## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...

Here the size of the marker is the baseline MPOWER score. The color is given by the HDI_MHI clustering presented in notebook 2.